<template>
  <div>
    <!-- 搜索 -->
    <div class="searchBox">
      <span class="hint">id</span>
      <el-input clearable v-model="searchForm.id" class="input" placeholder="请输入id"></el-input>
      <span class="hint">建筑名称</span>
      <el-input clearable v-model="searchForm.architecture_name" class="input" placeholder="请输入建筑名称"></el-input>
      <el-button class="searchBtn" type="primary" @click="searchBtn">搜索</el-button>
      <el-button type="warning" @click="refreshBtn">重置</el-button>
    </div>
    <page-main>
      <!-- <el-button size="mini" type="primary" @click="addEditSocialUnit">添加</el-button> -->
      <el-table :data="tableData" :default-sort="{ prop: 'id', order: 'descending' }" v-loading="tableDataLoading">
        <el-table-column label="建筑名称" prop="architecture_name"> </el-table-column>
        <el-table-column label="地上层数" prop="aboveground_floor"> </el-table-column>
        <el-table-column label="地下层数" prop="secret_floor"> </el-table-column>
        <el-table-column label="操作" fixed="right">
          <template #header>
            <el-button size="mini" type="primary" @click="addEditSocialUnit">添加</el-button>
          </template>
          <template #default="scope">
            <div>
              <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">修改</el-button>
              <el-button size="mini" type="info" @click="lookDetails(scope.row)">查看</el-button>
            </div>
            <div style="margin-top: 10px">
              <el-button type="warning" size="mini" @click="showFloorInfo(scope.row)">楼层管理</el-button>
              <el-popconfirm
                confirm-button-text="删除"
                cancel-button-text="取消"
                icon="el-icon-info"
                icon-color="red"
                title="确定删除？"
                @confirm="del(scope.row)"
                @cancel="cancelEvent"
              >
                <template #reference>
                  <el-button size="mini" type="danger">删除</el-button>
                </template>
              </el-popconfirm>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          :current-page="pagination.page"
          :total="total"
          :page-size="pagination.size"
          :page-sizes="pagination.sizes"
          :layout="pagination.layout"
          class="pagination"
          background
          @size-change="onSizeChange"
          @current-change="onCurrentChange"
        />
      </div>
    </page-main>
    <el-dialog
      v-model="dialogFormVisible"
      width="75%"
      @close="closeDialog"
      destroy-on-close
      :close-on-click-modal="false"
    >
      <el-form ref="childForm" :rules="rules" :model="formData">
        <el-row>
          <el-col :offset="1">
            <el-form-item label="建筑名称" prop="architecture_name">
              <el-input v-model="formData.architecture_name" :disabled="disabled" style="width: 400px"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" :offset="1">
            <el-form-item label="网格选择" prop="area_id">
              <el-cascader
                v-model="formData.area_id"
                :options="interLists"
                @change="handleChange"
                :props="cascaderProps"
                :emitPath="false"
                :disabled="disabled"
              ></el-cascader>
            </el-form-item>
          </el-col>
          <el-col></el-col>
          <el-col :span="6" :offset="1">
            <el-form-item label="地址" prop="address">
              <el-input v-model="formData.address" :disabled="disabled"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="14" :offset="1">
            <el-form-item label="单位坐标" prop="longitude">
              <div style="display: flex; align-item: center">
                <el-input style="width: 30%; margin-right: 1%" disabled v-model="formData.longitude"></el-input>
                <el-input style="width: 30%; margin-right: 1%" disabled v-model="formData.latitude"></el-input>
                <!-- <el-button :disabled="disabled" @click="getLatLng">定位</el-button> -->
                <el-button :disabled="disabled" @click="onLocation">定位</el-button>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="3" :offset="1">
            <el-form-item label="总面积（m²）" prop="total_area">
              <el-input
                v-model="formData.total_area"
                oninput="value=value.replace(/[^\d]/g,'')"
                :disabled="disabled"
                style="width: 110px"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="3" :offset="1">
            <el-form-item label="总楼层" prop="total_floor">
              <el-input
                v-model="formData.total_floor"
                oninput="value=value.replace(/[^\d]/g,'')"
                :disabled="disabled"
                :maxlength="3"
                style="width: 110px"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6" :offset="1">
            <el-form-item label="建造日期" prop="build_time">
              <el-date-picker v-model="formData.build_time" type="date" placeholder="选择日期" :disabled="disabled">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col></el-col>
          <el-col :span="4" :offset="1">
            <el-form-item label="建筑高度（m）" prop="building_height">
              <el-input
                v-model="formData.building_height"
                oninput="value=value.replace(/[^\d]/g,'')"
                :disabled="disabled"
                :maxlength="3"
                style="width: 110px"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4" :offset="1">
            <el-form-item label="建筑面积（m²）" prop="building_area">
              <el-input
                v-model="formData.building_area"
                oninput="value=value.replace(/[^\d]/g,'')"
                :disabled="disabled"
                style="width: 110px"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4" :offset="1">
            <el-form-item label="占地面积（m²）" prop="covere_area">
              <el-input
                v-model="formData.covere_area"
                oninput="value=value.replace(/[^\d]/g,'')"
                :disabled="disabled"
                style="width: 110px"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4" :offset="1">
            <el-form-item label="标准层面积（m²）" prop="floor_area">
              <el-input
                v-model="formData.floor_area"
                oninput="value=value.replace(/[^\d]/g,'')"
                :disabled="disabled"
                style="width: 110px"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col></el-col>
          <el-col :span="4" :offset="1">
            <el-form-item label="地上层数">
              <el-input
                v-model="formData.aboveground_floor"
                :maxlength="3"
                oninput="value=value.replace(/[^\d]/g,'')"
                :disabled="disabled || !!(formData.id && parseInt(floorOriginal.aboveground_floor, 10) > 0)"
                style="width: 110px"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4" :offset="1">
            <el-form-item label="地下层数">
              <el-input
                v-model="formData.secret_floor"
                :maxlength="2"
                oninput="value=value.replace(/[^\d]/g,'')"
                :disabled="disabled || !!(formData.id && parseInt(floorOriginal.secret_floor, 10) > 0)"
                style="width: 110px"
              ></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="4" :offset="1">
            <el-form-item label="地上层面积（m²）" prop="aboveground_area">
              <el-input
                v-model="formData.aboveground_area"
                oninput="value=value.replace(/[^\d]/g,'')"
                :disabled="disabled"
                style="width: 110px"
              ></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="4" :offset="1">
            <el-form-item label="地下层面积（m²）" prop="secret_area">
              <el-input
                v-model="formData.secret_area"
                oninput="value=value.replace(/[^\d]/g,'')"
                :disabled="disabled"
                style="width: 110px"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col></el-col>
          <el-col :span="3" :offset="1">
            <el-form-item label="建筑类别" prop="building_category">
              <el-select v-model="formData.building_category" filterable placeholder="请选择" :disabled="disabled">
                <el-option v-for="item in buildingCategory" :key="item" :label="item" :value="item"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="3" :offset="1">
            <el-form-item label="使用性质" prop="use_nature">
              <el-select v-model="formData.use_nature" filterable placeholder="请选择" :disabled="disabled">
                <el-option v-for="item in useNature" :key="item" :label="item" :value="item"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="3" :offset="1">
            <el-form-item label="结构类型" prop="structure_type">
              <el-select v-model="formData.structure_type" filterable placeholder="请选择" :disabled="disabled">
                <el-option v-for="item in structureType" :key="item" :label="item" :value="item"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="3" :offset="1">
            <el-form-item label="火灾危险性" prop="fire_hazard">
              <el-select v-model="formData.fire_hazard" filterable placeholder="请选择" :disabled="disabled">
                <el-option v-for="item in fireHazard" :key="item" :label="item" :value="item"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="3" :offset="1">
            <el-form-item label="耐火等级" prop="fire_rating">
              <el-select v-model="formData.fire_rating" filterable placeholder="请选择" :disabled="disabled">
                <el-option v-for="item in storageNature" :key="item" :label="item" :value="item"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <!-- 社会单位选择 -->
          <!-- 经纬度 -->

          <!-- <el-col :span="12" :offset="1">
            <el-form-item label="备注" prop="remarks">
              <el-input
                type="textarea"
                placeholder="请输入备注"
                v-model="formData.remarks"
                size="medium"
                show-word-limit
                :disabled="disabled"
               ></el-input>
            </el-form-item>
          </el-col> -->
          <el-col></el-col>
          <el-col :span="3" :offset="1">
            <el-form-item label="是否禁用" prop="st">
              <el-switch
                v-model="formData.st"
                active-text="是"
                inactive-text="否"
                :active-value="1"
                :inactive-value="0"
                :disabled="disabled"
              ></el-switch>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="submitForm" style="margin-left: 50px">确 定</el-button>
        </span>
      </template>
      <!-- 地图 -->
      <el-dialog v-model="mapIsShow" destroy-on-close>
        <div class="mapBox">
          <div class="search">
            <span type="primary">搜索</span>
            <el-input placeholder="请输入内容" v-model="searchInput" @keyup.enter="inputChange">
              <template #prefix>
                <i class="el-input__icon el-icon-search"></i>
              </template>
            </el-input>
          </div>
          <div id="container"></div>
          <div class="btnBox">
            <el-button @click="cancelMap">取消</el-button>
            <el-button type="primary" class="btn" @click="mapIsShow = false" style="margin-left: 50px">确定</el-button>
          </div>
        </div>
      </el-dialog>
    </el-dialog>
    <!-- 分页 -->
    <el-dialog v-model="floorInfoDialog" width="75%" close-on-click-modal>
      <el-table :data="floorTableData" border style="width: 100%">
        <el-table-column prop="id" label="ID" width="80"> </el-table-column>
        <el-table-column prop="floor_name" label="楼层名称"> </el-table-column>
        <el-table-column prop="floor_index" label="楼层数值"> </el-table-column>
        <el-table-column prop="floor_area" label="楼层总面积"> </el-table-column>
        <el-table-column prop="floor_height" label="楼层高度"> </el-table-column>
        <el-table-column prop="floor_room_count" label="楼层房间数量"> </el-table-column>
        <el-table-column prop="floor_is_refuge" label="是否避难层">
          <template #default="scope">
            <span>{{ Number(scope.row.floor_is_refuge) ? '是' : '否' }}</span>
          </template>
        </el-table-column>
        <el-table-column>
          <template #header>
            <el-button size="mini" type="primary" @click="addEditFloorInfoDialog = true">添加</el-button>
          </template>
          <template #default="scope">
            <el-button size="mini" @click="editFloorInfo(scope.row)">修改</el-button>
            <el-popconfirm
              confirm-button-text="删除"
              cancel-button-text="取消"
              icon="el-icon-info"
              icon-color="red"
              title="确定删除？"
              @confirm="deleteFloorInfo(scope.row)"
            >
              <template #reference>
                <el-button size="mini" type="danger">删除</el-button>
              </template>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          @current-change="getFloorData"
          v-model:currentPage="floorTableDataInfo.page"
          :page-count="floorTableDataInfo.total_page"
          :total="floorTableDataInfo.total"
          layout="total,prev, pager, next, jumper"
          background
        >
        </el-pagination>
      </div>
    </el-dialog>
    <!-- 楼层添加修改 -->
    <el-dialog
      v-model="addEditFloorInfoDialog"
      close-on-click-modal
      destroy-on-close
      @close="addEditFloorInfoDialogCloseEvent"
    >
      <el-form :model="floorParams" :rules="floorRules" ref="floorInfoForm">
        <el-row>
          <el-col :span="6">
            <el-form-item prop="floor_name" label="楼层名称">
              <el-input v-model="floorParams.floor_name"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6" :offset="1">
            <el-form-item prop="floor_index" label="楼层数值">
              <el-input v-model="floorParams.floor_index"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6" :offset="1">
            <el-form-item prop="floor_area" label="楼层总面积">
              <el-input v-model="floorParams.floor_area"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="floor_height" label="楼层高度">
              <el-input v-model="floorParams.floor_height"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6" :offset="1">
            <el-form-item prop="floor_room_count" label="楼层房间数量">
              <el-input v-model="floorParams.floor_room_count"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6" :offset="1">
            <el-form-item prop="floor_is_refuge" label="是否避难层">
              <el-switch
                v-model="floorParams.floor_is_refuge"
                :active-value="1"
                :inactive-value="0"
                active-text="是"
                inactive-text="否"
              >
              </el-switch>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item>
              <div style="display: flex; justify-content: center">
                <el-button type="primary" @click="submitFloorInfo">确定</el-button>
                <el-button @click="addEditFloorInfoDialog = false">取消</el-button>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
// 分页
import paginationMixin from '@/mixins/pagination'
export default {
  // 分页
  mixins: [paginationMixin],
  data() {
    return {
      searchForm: {
        id: '',
        architecture_name: ''
      },
      searchParams: {},
      mapIsShow: false,
      // 总页数
      total: 0,
      cascaderProps: {
        label: 'name',
        value: 'id',
        children: 'sub_item',
        checkStrictly: true,
        leaf: 'children'
      },
      // 结构类型
      structureType: [],
      //   火灾危险性
      fireHazard: [],
      // 建筑类别
      buildingCategory: [],
      // 耐火等级
      storageNature: [],
      // 使用性质
      useNature: [],
      disabled: false,
      upLoadImgData: {
        type: 'image'
      },
      upLoadFlieData: {
        type: 'file'
      },
      upDataUrl: import.meta.env.DEV ? '/proxy/' : import.meta.env.VITE_APP_API_BASEURL,
      tableData: [],
      tableDataLoading: false,
      search: '',
      tableDataInfo: '',
      fatherId: '',
      dialogFormVisible: false,
      formData: {
        architecture_name: '',
        aboveground_floor: '',
        secret_floor: '',
        area_id: '',
        address: '',
        aboveground_area: '',
        longitude: '',
        latitude: '',
        secret_area: '',
        build_time: '',
        fire_hazard: '',
        use_nature: '',
        building_category: '',
        structure_type: '',
        fire_rating: '',
        building_height: '',
        building_area: '',
        covere_area: '',
        floor_area: '',
        st: 0,
        total_area: '',
        total_floor: ''
        // remarks: '',
      },
      floorOriginal: {},
      rules: {
        architecture_name: [{ required: true, message: '请输入', trigger: 'blur' }],
        aboveground_floor: [{ required: true, message: '请输入', trigger: 'blur' }],
        secret_floor: [{ required: true, message: '请输入', trigger: 'blur' }],
        area_id: [{ required: true, message: '请选择', trigger: 'blur' }],
        address: [{ required: true, message: '请输入', trigger: 'blur' }],
        longitude: [{ required: true, message: '请选择', trigger: 'blur' }],
        latitude: [{ required: true, message: '请选择', trigger: 'blur' }],
        building_height: [{ required: true, message: '请输入', trigger: 'blur' }],
        total_area: [{ required: true, message: '请输入', trigger: 'blur' }],
        total_floor: [{ required: true, message: '请输入', trigger: 'blur' }]
        // remarks: [{ required: true, message: "请输入", trigger: "blur" }],
      },
      id: '',
      interLists: [],
      searchValue: '',
      jingwei: {
        longitude: '',
        latitude: ''
      },
      searchInput: '',
      buildingId: '',
      floorInfoDialog: false,
      floorTableData: [],
      floorTableDataInfo: '',
      addEditFloorInfoDialog: false,
      floorParams: {
        floor_name: '',
        floor_index: '',
        floor_area: '',
        floor_height: '',
        floor_room_count: '',
        floor_is_refuge: ''
      },
      floorRules: {
        floor_name: [{ required: true, message: '请输入', trigger: 'blur' }],
        floor_index: [{ required: true, message: '请输入', trigger: 'blur' }],
        floor_area: [{ required: true, message: '请输入', trigger: 'blur' }],
        floor_height: [{ required: true, message: '请输入', trigger: 'blur' }],
        floor_room_count: [{ required: true, message: '请输入', trigger: 'blur' }]
      }
    }
  },
  watch: {
    mapIsShow(newData) {
      if (!newData) {
        this.searchInput = ''
      }
    }
  },
  computed: {
    upLoadImgHeader() {
      return {
        'A-Token': this.$store.state.user.a_token,
        'U-Token': this.$store.state.user.u_token
      }
    }
  },
  created() {
    this.$api
      .get('/unit/RegionArea/getAreaTree', {
        params: {
          region_id: this.$store.state.user.user_info.region_id
        }
      })
      .then((res) => {
        this.interLists = res.data
      })
    this.fatherId = this.$route.params.id
    this.getDataList()
    this.getConfigList()
  },

  methods: {
    deleteFloorInfo(row) {
      this.$api.post('/unit/BuildingFloor/delete', { id: row.id }).then((res) => {
        this.$message.success('删除成功')
        this.addEditFloorInfoDialog = false
        this.getFloorData()
      })
    },
    editFloorInfo(row) {
      let temp = this.floorParams
      for (let key in temp) {
        temp[key] = row[key]
      }
      temp.id = row.id
      this.floorParams = temp
      this.addEditFloorInfoDialog = true
    },
    //楼层建筑关闭回调
    addEditFloorInfoDialogCloseEvent() {
      for (let key in this.floorParams) {
        this.floorParams[key] = ''
      }
    },
    submitFloorInfo() {
      this.$refs['floorInfoForm'].validate((valid) => {
        if (valid) {
          if (this.floorParams.id) {
            this.$api
              .post('/unit/BuildingFloor/edit', {
                building_id: this.buildingId,
                ...this.floorParams
              })
              .then((res) => {
                this.$message.success('操作成功')
                this.addEditFloorInfoDialog = false
                this.getFloorData()
              })
          } else {
            this.$api
              .post('/unit/BuildingFloor/add', {
                building_id: this.buildingId,
                ...this.floorParams
              })
              .then((res) => {
                this.$message.success('操作成功')
                this.addEditFloorInfoDialog = false
                this.getFloorData()
              })
          }
        } else {
          this.$message.error('请填写完整')
          return false
        }
      })
    },
    showFloorInfo(row) {
      this.buildingId = row.id
      this.floorInfoDialog = true
      this.getFloorData()
    },
    getFloorData(e) {
      let pageNum = 1
      if (e) {
        pageNum = e
      }
      this.$api
        .post('/unit/BuildingFloor/lists', {
          building_id: this.buildingId,
          page: pageNum,
          rows: 10
        })
        .then((res) => {
          this.floorTableData = res.data.lists
          delete res.data.lists
          this.floorTableDataInfo = res.data
        })
    },
    //   点击定位
    onLocation() {
      setTimeout(() => {
        this.$getMap(this)
      }, 200)
      this.mapIsShow = true
      let data = JSON.parse(JSON.stringify(this.formData))
      this.jingwei = {
        longitude: data.longitude,
        latitude: data.latitude
      }
    },
    inputChange() {
      this.$getMap(this, this.searchInput)
    },
    cancelMap() {
      //   this.formData.longitude = "";
      //   this.formData.latitude = "";
      this.formData.longitude = this.jingwei.longitude
      this.formData.latitude = this.jingwei.latitude
      this.mapIsShow = false
    },
    //   获取配置
    getConfigList() {
      this.$api.get('/unit/Setting/Config').then((res) => {
        this.structureType = res.data.structure_type
        this.fireHazard = res.data.fire_hazard
        this.buildingCategory = res.data.building_category
        this.storageNature = res.data.storage_nature
        this.useNature = res.data.use_nature
      })
    },
    //   经纬度
    getLatLng() {
      this.$getLocaion(returnCitySN['cip']).then((res) => {
        let temp = res.data.location.split(',')
        this.formData.longitude = temp[0] //经度
        this.formData.latitude = temp[1] //纬度
      })
    },
    safeFileUpSuccess(res) {
      this.formData.safe_promise_file = res.data.result
    },
    orgFileUpSuccess(res) {
      this.formData.org_promise_file = res.data.result
    },
    imgUpSuccess(res) {
      this.formData.escape_map = res.data.result
    },
    onExceed() {
      this.$message({
        showClose: true,
        message: '如需更改，请先删除已上传的',
        type: 'error'
      })
    },
    getDataList(page) {
      //   let pageNum = 1;
      //   if (page) {
      //     pageNum = page;
      //   }
      this.tableDataLoading = true
      let user_info = this.$store.state.user.user_info
      // 分页
      let params = {
        rows: this.pagination.size,
        page: this.pagination.page,
        region_id: user_info.region_id,
        ...this.searchParams
      }
      //   获取列表
      this.$api
        .post('/unit/Building/lists', params)
        .then((res) => {
          this.tableData = res.data.lists
          this.tableDataInfo = res.data
          this.total = res.data.total
        })
        .finally(() => {
          this.tableDataLoading = false
        })
    },
    // 搜索
    searchBtn() {
      this.searchParams = this.searchForm
      this.getDataList()
    },
    // 重置
    refreshBtn() {
      this.searchParams = {}
      this.searchForm = {
        id: '',
        architecture_name: ''
      }
      this.getDataList()
    },
    // 删除
    del(data) {
      let params = {
        id: data.id
      }
      this.$api.post('/unit/Building/delete', params).then((res) => {
        if (res.code === 200) {
          this.$message({
            type: 'success',
            message: res.msg
          })
        } else {
          this.$message({
            type: 'error',
            message: res.msg
          })
        }
        this.getDataList()
      })
    },
    // 点击详情
    lookDetails(row) {
      this.floorOriginal = {}
      this.disabled = true
      this.id = row.id
      this.point_id = row.point_id
      this.formData = JSON.parse(JSON.stringify(row))
      this.formData.build_time = this.formData.build_time * 1000
      this.dialogFormVisible = true
      if (row.fire_hazard == '0') {
        this.formData.fire_hazard = ''
      }
      if (row.building_category == '0') {
        this.formData.building_category = ''
      }
      if (row.use_nature == '0') {
        this.formData.use_nature = ''
      }
      if (row.structure_type == '0') {
        this.formData.structure_type = ''
      }
      if (row.fire_rating == '0') {
        this.formData.fire_rating = ''
      }
    },
    handleChange(e) {
      this.formData.area_id = e[Number(e.length) - 1]
    },
    handleEdit(index, row) {
      this.id = row.id
      this.point_id = row.point_id
      this.floorOriginal = {
        aboveground_floor: row.aboveground_floor,
        secret_floor: row.secret_floor
      }
      this.formData = JSON.parse(JSON.stringify(row))
      this.formData.build_time = this.formData.build_time * 1000
      this.dialogFormVisible = true
      if (row.fire_hazard == '0') {
        this.formData.fire_hazard = ''
      }
      if (row.building_category == '0') {
        this.formData.building_category = ''
      }
      if (row.use_nature == '0') {
        this.formData.use_nature = ''
      }
      if (row.structure_type == '0') {
        this.formData.structure_type = ''
      }
      if (row.fire_rating == '0') {
        this.formData.fire_rating = ''
      }
      //   this.getMap(this)
      //   this.$getMap(this);
    },
    handleSizeChange(e) {},
    handleCurrentChange(e) {
      this.getDataList(e)
    },
    addEditSocialUnit() {
      this.dialogFormVisible = true
      //   this.getMap(this)
      //   this.$getMap(this);
    },
    closeDialog() {
      this.$refs.childForm.resetFields()
      let temp = this.formData
      for (let key in temp) {
        temp[key] = ''
      }
      this.formData = temp
      this.floorOriginal = {}
      this.disabled = false
      this.id = ''
    },
    submitForm() {
      this.$refs.childForm.validate((valid) => {
        if (valid) {
          let region_id = this.$store.state.user.user_info.region_id
          let data = this.formData
          data.build_time = new Date(data.build_time).getTime() / 1000
          if (!data.id) {
            data.region_id = region_id
            this.$api.post('/unit/Building/add', data).then((res) => {
              if (res.code === 200) {
                this.$message({
                  type: 'success',
                  message: res.msg
                })
              } else {
                this.$message({
                  type: 'error',
                  message: res.msg
                })
              }
              this.getDataList()
              this.dialogFormVisible = false
            })
          } else {
            this.$api.post('/unit/Building/edit', data).then((res) => {
              if (res.code === 200) {
                this.$message({
                  type: 'success',
                  message: res.msg
                })
              } else {
                this.$message({
                  type: 'error',
                  message: res.msg
                })
              }
              this.getDataList()
              this.dialogFormVisible = false
            })
          }
        } else {
          this.$message.error('请填写完整')
          return false
        }
      })
    }
  }
}
</script>
<style scoped lang="scss">
.block {
  display: flex;
  justify-content: center;
  margin-top: 10px;
}
:deep(.el-textarea__inner) {
  height: 100px;
}
.mapBox {
  width: 100%;
  height: 600px;
  #container {
    z-index: 100;
    width: 100%;
    height: 500px;
  }
  .btnBox {
    margin-top: 20px;
    display: flex;
    justify-content: center;
  }
  .search {
    display: flex;
    span {
      width: 100px;
      line-height: 40px;
      text-align: center;
    }
  }
}
.searchBox {
  margin: 20px;
  display: flex;
  background-color: #fff;
  padding: 20px;
  .input {
    width: 10%;
    margin-right: 15px;
  }
  .hint {
    line-height: 40px;
    margin-right: 10px;
  }
  .searchBtn {
    background-color: #2d8cf0;
    color: #fff;
  }
}
// .block {
//     margin-top: 10px;
//     display: flex;
//     justify-content: center;
// }
</style>
